package com.example.demo.auto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;


public class MyBeanDefinitionRegister implements ImportBeanDefinitionRegistrar, BeanPostProcessor {

    Logger log = LoggerFactory.getLogger(MyBeanDefinitionRegister.class);

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
        if (log.isDebugEnabled()){
            log.debug("初始化自定义的BeanDefinitionRegister...");
        }
//        registry.registerBeanDefinition();
        RootBeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setBeanClassName(A.class.getName());
        registry.registerBeanDefinition("a", beanDefinition);

        if (log.isErrorEnabled()){
            log.error("初始化自定义的BeanDefinitionRegister...");
        }
    }
}
